package cn.edu.swu.dbcp.auth;

import cn.edu.swu.dbcp.repo.ResultSetVisitor;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;


public class userResultSetVistor implements ResultSetVisitor<user> {
    @Override
    public List<user> visit(ResultSet resultSet) throws SQLException {
        List<user> users = new ArrayList<>();
        // 取出所有ResultSet中所有user
        while (resultSet.next()) {
            user u = new user();
            u.setId(resultSet.getInt("id"));
            u.setName(resultSet.getString("name"));
            u.setPasswd(resultSet.getString("passwd"));
            u.setRole(resultSet.getString("role"));
            users.add(u);
        }
        // 返回user List
        return users;
    }
}
